package com.ghy.controller;

import com.ghy.dto.RoleInsertDTO;
import com.ghy.dto.RolePageDTO;
import com.ghy.dto.RoleUpdateDTO;
import com.ghy.vo.MenuSimpleListVO;
import com.ghy.vo.RoleSimpleListVO;
import com.mybatisflex.core.paginate.Page;
import com.ghy.dto.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import com.ghy.entity.Role;
import com.ghy.service.RoleService;

import java.util.List;

/**
 * 角色表 控制层。
 *
 * @author ghy
 * @since 2024-12-22
 */
@Tag(name = "角色")
@RestController
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @Operation(summary ="新增——单条",description ="新增一条角色记录")
    @PostMapping("insert")
    public boolean insert(@Validated @RequestBody RoleInsertDTO dto) {
        return roleService.insert(dto);
    }

    @Operation(summary ="查询——单条",description ="按主键查询一条角色记录")
    @GetMapping("select/{id}")
    public Role select(@PathVariable("id") Long id) {
        return roleService.select(id);
    }

    @Operation(summary = "查询——简单查询全部", description = "查询全部角色记录")
    @GetMapping("simpleList")
    public List<RoleSimpleListVO> simpleList() {
        return roleService.simpleList();
    }

    @Operation(summary ="查询——分页",description ="分页查询角色记录")
    @GetMapping("page")
    public Page<Role> page(@Validated RolePageDTO dto) {
        return roleService.page(dto);
    }

    @Operation(summary="修改——单条",description="按主键修改一条角色记录")
    @PutMapping("update")
    public boolean update(@RequestBody RoleUpdateDTO dto) {
        return roleService.update(dto);
    }

    @Operation(summary ="删除——单条",description ="按主键删除一条角色记录")
    @DeleteMapping("delete/{id}")
    public boolean delete(@PathVariable("id") Long id) {
        return roleService.delete(id);
    }

    @Operation(summary="删除——批量",description ="按主键批量删除角色记录")
    @DeleteMapping("deleteBatch")
    public boolean deleteBatch(@RequestParam("ids") List<Long> ids) {
        return roleService.deleteBatch(ids);
    }

    @Operation(summary ="查询——菜单ID列表",description="按主键查询角色的全部菜单ID列表")
    @GetMapping("listMenuIds/{id}")
    public List<Long> listMenuIds(@PathVariable("id") Long id) {
        return roleService.listMenuIds(id);
    }

    @Operation(summary="修改——菜单列表",description="按主键修改角色的菜单列表记录")
    @PutMapping("updateMenus")
    public  boolean updateMenus(@RequestBody RoleUpdateDTO dto){
        return roleService.updateMenus(dto);
    }


}
